﻿Imports System.Data.OleDb
Imports System.Globalization

Public Class AdvancedSearch
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try


            If (drpCategory.SelectedValue = "Quiz") Then
                pnlQuizPanel.Visible = True
                pnlProfile.Visible = False
            ElseIf (drpCategory.SelectedValue = "Profile") Then
                pnlQuizPanel.Visible = False
                pnlProfile.Visible = True
            End If
        Catch ex As Exception

        End Try
    End Sub


    Protected Sub btnSearchQuiz_Click(sender As Object, e As EventArgs) Handles btnSearchQuiz.Click
        Try


            If (drpUsers.SelectedValue = -1) Then
                'search all teachers

                Dim selectedDate As DateTime = Convert.ToDateTime(txtDate.Text)

                Dim mysearch As QuizManagement = New QuizManagement()

                Dim dr As OleDbDataReader = mysearch.SelectQuizSearchByQuizContentDate(txtSearchContent.Text, selectedDate)

                If dr.HasRows Then
                    rptResults.DataSource = dr
                    rptResults.DataBind()
                    lblMessage.Text = ""
                    rptResults.Visible = True
                Else
                    rptResults.Visible = False
                    lblMessage.Text = "No results"
                End If
            ElseIf (drpUsers.SelectedValue <> -1) Then



                Dim selectedDate As DateTime = Convert.ToDateTime(txtDate.Text)

                Dim mysearch As QuizManagement = New QuizManagement()

                Dim dr As OleDbDataReader = mysearch.SelectQuizSearchByQuizContentDateByTeacher(txtSearchContent.Text, selectedDate, Convert.ToInt32(drpUsers.SelectedValue))

                If dr.HasRows Then
                    rptResults.DataSource = dr
                    rptResults.DataBind()
                    lblMessage.Text = ""

                    rptResults.Visible = True

                Else
                    lblMessage.Text = "No results"
                    rptResults.Visible = False
                End If

            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnSearchProfile_Click(sender As Object, e As EventArgs) Handles btnSearchProfile.Click
        Try


            If (drpUserType.SelectedValue <> "-1") Then
                Dim mySearch As ProfilesManagement = New ProfilesManagement()
                Dim dr As OleDbDataReader = mySearch.SelectSearchProfileByUserRole(txtSearchContent.Text, drpUserType.SelectedValue)
                If dr.HasRows Then
                    rptProfiles.DataSource = dr
                    rptProfiles.DataBind()
                    lblMessage.Text = ""
                    rptProfiles.Visible = True

                Else
                    lblMessage.Text = "No results"
                    rptProfiles.Visible = False

                End If
            Else
                Dim mySearch As ProfilesManagement = New ProfilesManagement()
                Dim dr As OleDbDataReader = mySearch.SelectSearchProfile(txtSearchContent.Text)

                If dr.HasRows Then
                    rptProfiles.DataSource = dr
                    rptProfiles.DataBind()

                    rptProfiles.Visible = True

                Else
                    lblMessage.Text = "No results"
                    rptProfiles.Visible = False


                End If

            End If
        Catch ex As Exception

        End Try
    End Sub
End Class